﻿using DirectSell.Common.Url;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Webdiyer.WebControls.Mvc;

namespace DirectSell.Common.Page
{
    /// <summary>
    /// List转分页Model
    /// </summary>
    public static class ListToPageModel
    {
        /// <summary>
        /// List转为分页model 郭文昊 2018年11月23日22:50:05
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public static PagedList<T> PageList<T>(this IList<T> list, int? page)
        {
            int pageNumber = page ?? 1;

            int pageSize = CommonConfig.PageSize;

            return list.ToPagedList(pageNumber, pageSize);
        }
        /// <summary>
        /// List转为分页model 异步
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public async static Task<PagedList<T>> ToPageListAsync<T>(this IList<T> list, int? page)
        {
            int pageNumber = page ?? 1;

            int pageSize = CommonConfig.PageSize;

            var result = await Task.Run(()=>  list.ToPagedList(pageNumber, pageSize));

            return result;
        }
    }
}
